package com.shopping_back.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shopping_back.common.Result;
import com.shopping_back.pojo.entity.OrderMain;
import com.shopping_back.pojo.entity.SeckillItem;
import com.shopping_back.service.ISeckillItemService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 秒杀商品表 前端控制器
 * </p>
 *
 * @author Jack
 * @since 2025-07-12
 */
@RestController
@RequestMapping("/api/seckill-item")
@RequiredArgsConstructor
public class SeckillItemController {
    private final ISeckillItemService seckillItemService;

    @GetMapping("/activity")
    public Result getSeckillActivity(@RequestParam Long activityId) {
        return Result.success(seckillItemService.getSeckillActivity(activityId));
    }

    @GetMapping("/items")
    public Result getSeckillItems(@RequestParam Long activityId,
                                  @RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer size) {
        return Result.success(seckillItemService.getSeckillItems(activityId, page, size));
    }

    @PostMapping("/placeOrder")
    public Result placeSeckillOrder(@RequestParam Long userId,
                                    @RequestParam Long activityId,
                                    @RequestParam Long skuId,
                                    @RequestParam Integer quantity) {
        return seckillItemService.placeSeckillOrder(userId, activityId, skuId, quantity);
    }
}
